#include "opResMessage.h"
#include "jsonUtils.h"

OpResMessage::OpResMessage(MtpProtocol* packet) : MtpMessage(packet)
{

}

OpResMessage::OpResMessage(const bool& success, MtpMessage* src)
	: MtpMessage(new MtpProtocol(L"opRes", (MtpProtocol*)src->getPacket())), opRes(success)
{

}

OpResMessage::OpResMessage(const bool& success, const String& message, MtpMessage* src)
	: MtpMessage(new MtpProtocol(L"opRes", (MtpProtocol*)src->getPacket())),opRes(success,message)
{

}

OpResMessage::OpResMessage(const bool& success, const String& message, const int& version, const uint32_t& commandId)
	: MtpMessage(new MtpProtocol(L"opRes",version,commandId)),opRes(success,message)
{
}

void OpResMessage::decodeBody()
{
	MtpMessage::decodeBody();
	opRes.jsonDeserialize(jsonContent);
}

void OpResMessage::encodeBody()
{
	jsonContent = JsonUtils::jsonStr(opRes.jsonSerialize());
	MtpMessage::encodeBody();
}
